*Replication package for VannoniAshMorelli2019

*ssc install binscatter
*ssc install reghdfe
*ssc install outreg2
*ssc install grstyle
*ssc install ftools
*ssc install lgraph

set scheme aspen  /* in order to reproduce the graphs as they look like in the paper the user generated scheme aspen (provided in the replication package) needs to be used */


grstyle init
grstyle set plain, horizontal grid

clear
set more off
use "VannoniAshMorelli_2019.dta", clear

xtset state year, yearly delta(2)

*\Table 2

label variable civil_service_reform_biennium1    "Civil Service"

foreach x in  log_provisions     {

reghdfe  `x' civil_service_reform_biennium1 drafting_system divided_gov_biennium  i.year i.state#c.year, a(state) cl(state)
outreg2 using Table2, tex replace keep(civil_service_reform_biennium1 drafting_system divided_gov_biennium ) label   ctitle(Leg Detail)  nocons    addtext(State FE, X, Time FE, X, State-Specific Trends, X) noaster   nonotes addnote(SE clustered by `e(clustvar)')
reghdfe  `x' civil_service_reform_biennium1 drafting_system divided_gov_biennium L1.`x' i.year , a(state) cl(state)
outreg2 using Table2, tex append keep(civil_service_reform_biennium1 drafting_system divided_gov_biennium ) label   ctitle(Leg Detail)  nocons    addtext(State FE, X, Time FE, X, Lagged DV, X)  noaster   nonotes addnote(SE clustered by `e(clustvar)')
reghdfe  `x' civil_service_reform_biennium1 drafting_system divided_gov_biennium treat_dummy  i.year i.state#c.year, a(state) cl(state)
outreg2 using Table2, tex append keep(civil_service_reform_biennium1 drafting_system divided_gov_biennium ) label   ctitle(Leg Detail)  nocons    addtext(State FE, X, Time FE, X, State-Specific Trends, X, Reform Year, X) noaster   nonotes addnote(SE clustered by `e(clustvar)')
reghdfe  `x' civil_service_reform_biennium1 drafting_system divided_gov_biennium civil_service_reform_biennium1#divided_gov_biennium  i.year i.state#c.year, a(state) cl(state)
outreg2 using Table2, tex append keep(civil_service_reform_biennium1 drafting_system divided_gov_biennium ) label   ctitle(Leg Detail)  nocons    addtext(State FE, X, Time FE, X, State-Specific Trends, X, Interaction, X) noaster   nonotes addnote(SE clustered by `e(clustvar)')
reghdfe  `x' civil_service_reform_biennm_rpl drafting_system divided_gov_biennium  i.year i.state#c.year, a(state) cl(state)
outreg2 using Table2, tex append keep(civil_service_reform_biennm_rpl drafting_system divided_gov_biennium ) label   ctitle(Leg Detail -Repeal)  nocons    addtext(State FE, X, Time FE, X, State-Specific Trends, X) noaster   nonotes addnote(SE clustered by `e(clustvar)')
}

*\Figure 3
gen mandD = D.civil_service_reform_biennium1
gen mandyear1 = year if mandD == 1
bysort state: egen mandyear = max(mandyear1)
bysort state: gen mandtime = year - mandyear
gen mand10 = mandtime >= 1 & mandtime <= 5
gen mand10window = mandtime >= -4 & mandtime <= 5

areg  log_provisions drafting_system divided_gov_biennium  i.year i.state#c.year, absorb(state) cl(state)
predict resid_provisions, residuals

grstyle set margin "0pt -30pt 0pt 0pt": axis_title
lgraph resid_provisions mandtime if mand10window, errortype(90) ytitle("Legislative Detail") xtitle("Bienniums before and after Civil Service Reform") xline(0, lcolor(gray) lpattern(dash)) yline(-.084, lcolor(gray) lpattern(dash))

graph export Figure3.pdf, replace

*\Table 3

label variable unified_gov_biennium    "Unified Govt"

reghdfe del_final unified_gov_biennium, a(state year) cl(state)
outreg2 using Table3, tex replace  keep(unified_gov_biennium) label ctitle(Exec Del) nocons bdec(4) sdec(3)  addtext(State FE, X, Year FE, X) noaster   nonotes addnote(SE clustered by `e(clustvar)')

reghdfe del_final unified_gov_biennium  c.year#i.state , a(year state) cl(state)
outreg2 using Table3, tex append  keep(unified_gov_biennium) label ctitle(Exec Del) nocons  bdec(4) sdec(4)  addtext(State FE, X, Year FE, X, State-time Trends, X) noaster   nonotes addnote(SE clustered by `e(clustvar)')

reghdfe del_final unified_gov_biennium   L1.del_final, a(year state) cl(state)
outreg2 using Table3, tex append  keep(unified_gov_biennium) label ctitle(Exec Del) nocons bdec(4) sdec(4) addtext(State FE, X, Year FE, X, Lagged DV, X) noaster   nonotes addnote(SE clustered by `e(clustvar)')

reghdfe del_final unified_gov_biennium c.year#i.state civil_service_reform_biennium1, a(year state) cl(state)
outreg2 using Table3, tex append  keep(unified_gov_biennium) label ctitle(Exec Del) nocons bdec(3) sdec(4)   addtext(State FE, X, Year FE, X, State-time Trends, X, Civil Service, X) noaster   nonotes addnote(SE clustered by `e(clustvar)')

reghdfe log_delegation_ratio1 unified_gov_biennium c.year#i.state civil_service_reform_biennium1, a(year state) cl(state)
outreg2 using Table3, tex append  keep(unified_gov_biennium) label ctitle(Del Ratio) nocons bdec(5) sdec(4)   addtext(State FE, X, Year FE, X, State-time Trends, X, Civil Service, X) noaster   nonotes addnote(SE clustered by `e(clustvar)')

reghdfe log_delegation_ratio unified_gov_biennium c.year#i.state civil_service_reform_biennium1, a(year state) cl(state)
outreg2 using Table3, tex append  keep(unified_gov_biennium) label ctitle(Del Ratio Gov) nocons  bdec(3) sdec(3)  addtext(State FE, X, Year FE, X, State-time Trends, X, Civil Service, X) noaster   nonotes addnote(SE clustered by `e(clustvar)')

*\Figure 2 

gen prop_modal=strict_modal_gov/(delegation_gov) 

keep if year>1899

grstyle set margin "0pt 0pt 0pt 0pt": axis_title
lgraph prop_modal year, yline(1) errortype(95) xtitle("Year") ytitle("Ratio: Lexicon Measure / Parser Measure")
graph export Figure2.pdf, replace

*\Figure 4

collapse (mean)  log_delegation_ratio1 log_constraint_ratio1, by(year)

tsline log_delegation_ratio1,tlabel(1900(20)2000,grid )  saving(gr1.gph, replace) ytitle(" ") subtitle("Delegation Ratio over Time") xtitle("Year")

tsline log_constraint_ratio1,tlabel(1900(20)2000,grid )  saving(gr2.gph, replace) ytitle(" ") subtitle("Constraint Ratio over Time") xtitle("Year")

gr combine gr1.gph  gr2.gph 
graph export Figure4.pdf, replace

clear
set more off
use VannoniAshMorelli_2019_validation

*\Figure 1

binscatter franchino_delegations delegation , ytitle("Hand-Annotated Delegations") xtitle("Machine-Annotated Delegations") saving(gr3.gph, replace)

binscatter   franchino_constraints constraint, ytitle("Hand-Annotated Constraints ") xtitle("Machine-Annotated Constraints")  saving(gr4.gph, replace)

gr combine gr3.gph  gr4.gph, col(1)
graph export Figure1.pdf, replace

reg franchino_delegations delegation
* R2 = .44

reg franchino_constraints constraint
* R2 = .06
